//
//  UComicTCell.swift
//  U17
//
//  Created by charles on 2017/11/8.
//  Copyright © 2017年 None. All rights reserved.
//

import UIKit

class MessageCell: UBaseTableViewCell {
    var spinnerName: String?
    private lazy var timeLabel: LabelPadding = {
        let el = LabelPadding()
        el.textInsets = UIEdgeInsets(top: 8, left: 16, bottom: 8, right: 16)
        el.textColor = UIColor.white
        el.backgroundColor = UIColor.colHui
        el.font = UIFont.systemFont(ofSize: 14)
        el.textAlignment = NSTextAlignment.center
        
        el.sizeToFit()
        el.layer.masksToBounds = true
        el.layer.cornerRadius = 16
        return el
    }()
    lazy var msgView: UIView = {
        let el = UIView()
        el.backgroundColor = UIColor.white
        el.layer.masksToBounds = true
        el.layer.cornerRadius = 6
        return el
    }()
    private lazy var snLabel: LabelPadding = {
        let el = LabelPadding()
        el.textColor = UIColor.colHui
        el.textInsets = UIEdgeInsets(top: 15, left: 30, bottom: 15, right: 30)
        el.font = UIFont.small
        el.numberOfLines = 1
        el.lineBreakMode = NSLineBreakMode.byWordWrapping
        el.sizeToFit()
        return el
    }()
    private lazy var commitLabel: LabelPadding = {
        let el = LabelPadding()
        el.textColor = UIColor.colBlack
        el.textInsets = UIEdgeInsets(top: 10, left: 20, bottom: 10, right: 20)
        el.backgroundColor = UIColor.white
        el.font = UIFont.systemFont(ofSize: 16)
        el.textAlignment = NSTextAlignment.left
        el.numberOfLines = 0
        el.lineBreakMode = NSLineBreakMode.byWordWrapping
        el.sizeToFit()
        el.layer.masksToBounds = true
        el.layer.cornerRadius = 6
        return el
    }()
    
    
    override func configUI() {
        separatorInset = .zero
         contentView.backgroundColor = UIColor.background
        contentView.addSubview(timeLabel)
        timeLabel.snp.makeConstraints {
            $0.top.equalTo(size20)
            $0.centerX.equalToSuperview()
        }
        contentView.addSubview(msgView)
        msgView.snp.makeConstraints {
            $0.top.equalTo(timeLabel.snp.bottom).offset(size20)
            $0.height.greaterThanOrEqualTo(size40)
            $0.left.equalTo(size20)
            $0.right.equalTo(-size20)
            $0.bottom.lessThanOrEqualToSuperview().offset(-size10)
        }
        msgView.addSubview(commitLabel)
        commitLabel.snp.makeConstraints {
            $0.top.equalToSuperview().offset(size10)
            $0.left.equalTo(size20)
            $0.right.equalTo(-size20)
            $0.bottom.lessThanOrEqualToSuperview().offset(-1)
        }
    }

    var model: MsgModel? {
        didSet {
            guard let model = model else { return }
            timeLabel.text = model.createTime
            commitLabel.text = model.message
        }
    }
    
}
